from django.db import models
from django.utils import timezone

class HotWord(models.Model):
    keyword = models.CharField(max_length=100, verbose_name='关键词')
    category = models.CharField(max_length=50, verbose_name='分类')
    hot_value = models.IntegerField(default=0, verbose_name='热度值')
    similarity = models.FloatField(default=0, verbose_name='相似度')
    created_at = models.DateTimeField(default=timezone.now, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    
    class Meta:
        db_table = 'hot_words'
        verbose_name = '热点词'
        verbose_name_plural = '热点词'
        ordering = ['-hot_value', '-created_at']
    
    def __str__(self):
        return f"{self.keyword} ({self.category})"

class CrawlerLog(models.Model):
    STATUS_CHOICES = [
        ('running', '运行中'),
        ('success', '成功'),
        ('failed', '失败'),
    ]
    
    status = models.CharField(max_length=20, choices=STATUS_CHOICES, verbose_name='状态')
    message = models.TextField(blank=True, verbose_name='消息')
    created_at = models.DateTimeField(default=timezone.now, verbose_name='创建时间')
    
    class Meta:
        db_table = 'crawler_logs'
        verbose_name = '爬虫日志'
        verbose_name_plural = '爬虫日志'
        ordering = ['-created_at']
    
    def __str__(self):
        return f"{self.status} - {self.created_at.strftime('%Y-%m-%d %H:%M:%S')}"